#pragma once

#include "type.h"
#include "workqueue.h"
#include "vector3.h"

namespace ChunkSystem
{
	class ChunkSpace;
	class ChunkCamera;
	class ChunkFileSerializer;

	enum{ m_gChunkSeekChannel = 100 };
	enum{ m_gChunkLoadChannel = 101 };

	//request for searching
	struct ChunkSeekRequestData
	{
		ChunkSpace*		m_pWorkSpace;
		ChunkFileSerializer* m_pChunkFileSerializer;
		Common::Vector3 m_vTargetPos;
	};

	class ChunkSeeker
		:public Common::WorkQueue::RequestHandler
	{
	public:
		ChunkSeeker();
		virtual ~ChunkSeeker(void);

		virtual bool canHandleRequest(const Common::WorkQueue::Request* req, const Common::WorkQueue* srcQ);
		virtual Common::WorkQueue::Response* handleRequest(const Common::WorkQueue::Request* req, const Common::WorkQueue* srcQ);

		Chunk*	GetFoundSeed(void) const;
		void ResetSeed(void);

	private:
		Chunk*				m_pFoundSeed;
	};

	class ChunkSeekResponseHandler
		:public Common::WorkQueue::ResponseHandler
	{
	public:
		ChunkSeekResponseHandler(void);
		virtual ~ChunkSeekResponseHandler(void);

		virtual bool canHandleResponse(const Common::WorkQueue::Response* response, const Common::WorkQueue* srcQ);
		virtual void handleResponse(const Common::WorkQueue::Response* response, const Common::WorkQueue* srcQ); 
	};


	struct ChunkLoadRequestData
	{
		Chunk*			 m_pLoadTarget;
	};

	class ChunkLoader
		:public Common::WorkQueue::RequestHandler
	{
	public:
		ChunkLoader(void);
		virtual ~ChunkLoader(void);

		virtual bool canHandleRequest(const Common::WorkQueue::Request* req, const Common::WorkQueue* srcQ);
		virtual Common::WorkQueue::Response* handleRequest(const Common::WorkQueue::Request* req, const Common::WorkQueue* srcQ); 
	};
}